/*package com.quanyan.thread;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map.Entry;

import org.apache.log4j.Logger;

import com.lolaage.config.Configure;
import com.lolaage.config.IConfigure;
import com.quanyan.cache.SocketChannelMng;
import com.quanyan.entity.ChannelContext;

public class CommunicationStateMonitorThread extends Thread {
    private static final Logger logger = Logger.getLogger(CommunicationStateMonitorThread.class);
    
    private static int COMM_CHECK_INTERVAL;
    
    private static int CHANNEL_TIME_OUT;
    
    private static int INVALID_CHANNEL_TIME_OUT;
    
    static {
        
        IConfigure configure = Configure.getInstance();
        COMM_CHECK_INTERVAL = configure.readInt("externalp_interface", "comm_check_interval");
        
        CHANNEL_TIME_OUT = configure.readInt("externalp_interface", "channel_time_out");
        
        INVALID_CHANNEL_TIME_OUT = configure.readInt("externalp_interface", "invalid_channel_time_out");
        
    }
    
    public static void main(String[] args) {
        IConfigure configure = Configure.getInstance();
        int a = configure.readInt("external_interfacep", "channel_time_out");
        System.out.println(a);
    }
    
    public void run() {
        while (true) {
            ArrayList<ChannelContext> list = new ArrayList<ChannelContext>();
            try {
                logger.debug("Start to check the communication state");
                SocketChannelMng socketChannelMng = SocketChannelMng.getInstance();
                // 未登录用户
                Iterator<Entry<String, ChannelContext>> it =
                    socketChannelMng.getInvalidSocketChannelMap().entrySet().iterator();
                while (it.hasNext()) {
                    try {
                        Entry<String, ChannelContext> entry = it.next();
                        ChannelContext context = entry.getValue();
                        // 超过指定时间没有通讯，则关闭通道
                        long timeDiff = System.currentTimeMillis() - context.getOperateTime();
                        if (timeDiff >= INVALID_CHANNEL_TIME_OUT) {
                            System.out.println("未验证时间设置：" + INVALID_CHANNEL_TIME_OUT);
                            System.out.println("验证时间设置:" + CHANNEL_TIME_OUT);
                            System.out.println("上一次通讯时间" + context.getOperateTime());
                            System.out.println("***时间差" + timeDiff);
                            // 加入待关闭集合，为避免java.util.ConcurrentModificationException
                            System.out.println("未验证用户通道关闭,sessionId:" + entry.getKey());
                            list.add(context);
                            // map.remove(key); //ConcurrentModificationException
                            it.remove(); // OK
                        }
                    }
                    catch (Throwable e) {
                        logger.error(e.getMessage(), e);
                    }
                }
                
                // 登录用户
                Iterator<Entry<Long, ChannelContext>> it2 =
                    socketChannelMng.getSocketChannelMap().entrySet().iterator();
                while (it2.hasNext()) {
                    try {
                        Entry<Long, ChannelContext> entry = it2.next();
                        ChannelContext context = entry.getValue();
                        // 超过指定时间没有通讯，则关闭通道
                        long timeDiff = System.currentTimeMillis() - context.getOperateTime();
                        if (timeDiff >= CHANNEL_TIME_OUT) {
                            // System.out.println("上一次通讯时间" + context.getOperateTime());
                            // System.out.println("***时间差" + timeDiff);
                            // 加入待关闭集合，为避免java.util.ConcurrentModificationException
                            System.out.println("验证用户通道关闭,用户id：" + entry.getKey());
                            list.add(context);
                            // map.remove(key); //ConcurrentModificationException
                            it.remove(); // OK
                        }
                    }
                    catch (Throwable e) {
                        logger.error(e.getMessage(), e);
                    }
                }
                
                // 迭代结合，关闭channel
                for (ChannelContext context : list) {
                    try {
                        context.getChannel().close();
                    }
                    catch (Throwable e) {
                        logger.error(e.getMessage(), e.getCause());
                    }
                }
            }
            catch (Throwable e) {
                logger.error(e.getMessage(), e);
            }
            finally {
                if (list != null) {
                    list.clear();
                    list = null;
                }
            }
            
            try {
                Thread.sleep(COMM_CHECK_INTERVAL);
            }
            catch (Throwable e) {
                logger.error(e.getMessage(), e);
            }
            
        }
    }
}
*/